#include "BoundingBox.h"

BoundingBox::BoundingBox() {
    corner = vec3(0.0f);
    lengths = vec3(0.0f);
    model = new ModelRender(false);
}

BoundingBox::BoundingBox(vec3 bottomLeftForwardCorner, vec3 initLengths) {
    corner = bottomLeftForwardCorner;
    lengths = initLengths;
    model = new ModelRender(false);
}

void BoundingBox::SetModelData(RenderManager rManager) {
    model->SetManager(rManager);
    model->Initialize("models/cube.obj");
}

bool BoundingBox::CollidesWith(BoundingBox other) {
    vec3 otherCorner = other.GetCorner();
    vec3 otherLengths = other.GetLengths();
    bool topBounds = (corner.y + lengths.y > otherCorner.y);
    bool bottomBounds = (corner.y < otherCorner.y + otherLengths.y);
    bool leftBounds = (corner.x + lengths.x > otherCorner.x);
    bool rightBounds = (corner.x < otherCorner.x + otherLengths.x);
    bool farBounds = (corner.z < otherCorner.z + otherLengths.z);
    bool closeBounds = (corner.z + lengths.z > otherCorner.z);
        
    return (topBounds && bottomBounds) && (leftBounds && rightBounds) && (farBounds && closeBounds);
}

void BoundingBox::Render() {
    model->StackStack();
        model->Translate(corner);
        model->Scale(lengths);
        model->Draw(0.0f);
    model->EndStack();
}
